package com.firstappdemo.config.mybits;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import com.baomidou.mybatisplus.extension.plugins.SqlExplainInterceptor;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Properties;

//@Configuration
@Data
public class MybatisPlusConfig {

    //    @Autowired
    MybatisPlusProperty mybatisPlusProperty;

    /**
     * 分页插件
     */
//    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    //    @Bean
//    @Profile({"dev"})// 设置 dev环境开启 打印sql
    public PerformanceInterceptor performanceInterceptor() {
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        performanceInterceptor.setFormat(true);
        performanceInterceptor.setMaxTime(300);
        return performanceInterceptor;
    }

    //    @Bean
//    @Profile({"dev"})//作用是分析 处理 DELETE UPDATE 语句， 防止小白或者恶意 delete update 全表操作！
    public SqlExplainInterceptor sqlExplainInterceptor() {
        SqlExplainInterceptor sqlExplainInterceptor = new SqlExplainInterceptor();
        Properties prop = new Properties();
        prop.put("stopProceed", StringUtils.isEmpty(mybatisPlusProperty.getStopProceed()) ? false : true);
        sqlExplainInterceptor.setProperties(prop);
        return new SqlExplainInterceptor();
    }
}
